| @@ -148,6 +148,9 @@ class AgentsController < ApplicationController | ||
| 148 | 148 | else | 
| 149 | 149 | @agent = agents.build | 
| 150 | 150 | end | 
| 151 | + | |
| 152 | + @agent.scenario_ids = [params[:scenario_id]] if params[:scenario_id] && current_user.scenarios.find_by(id: params[:scenario_id]) | |
| 153 | + | |
| 151 | 154 | initialize_presenter | 
| 152 | 155 |  | 
| 153 | 156 | respond_to do |format| | 
| @@ -237,14 +240,14 @@ class AgentsController < ApplicationController | ||
| 237 | 240 | if @agent && !@agent.destroyed? | 
| 238 | 241 | path = agent_path(@agent) | 
| 239 | 242 | end | 
| 240 | -    when /\A#{Regexp::escape scenarios_path}\/\d+\Z/, agents_path | |
| 243 | +    when /\A#{Regexp::escape scenarios_path}\/\d+\z/, agents_path | |
| 241 | 244 | path = ret | 
| 242 | 245 | end | 
| 243 | 246 |  | 
| 244 | 247 | if path | 
| 245 | 248 | redirect_to path, notice: message | 
| 246 | 249 | else | 
| 247 | - super agents_path, notice: message | |
| 250 | + redirect_to agents_path, notice: message | |
| 248 | 251 | end | 
| 249 | 252 | end | 
| 250 | 253 |  | 
| @@ -48,6 +48,15 @@ class JobsController < ApplicationController | ||
| 48 | 48 | end | 
| 49 | 49 | end | 
| 50 | 50 |  | 
| 51 | + def destroy_all | |
| 52 | + Delayed::Job.delete_all | |
| 53 | + | |
| 54 | + respond_to do |format| | |
| 55 | +      format.html { redirect_to jobs_path, notice: "All jobs removed." } | |
| 56 | +      format.json { render json: '', status: :ok } | |
| 57 | + end | |
| 58 | + end | |
| 59 | + | |
| 51 | 60 | private | 
| 52 | 61 |  | 
| 53 | 62 | def running? | 
| @@ -79,6 +79,10 @@ | ||
| 79 | 79 | <%= link_to destroy_failed_jobs_path, class: "btn btn-default", method: :delete do %> | 
| 80 | 80 | <span class="glyphicon glyphicon-trash"></span> Remove failed jobs | 
| 81 | 81 | <% end %> | 
| 82 | + | |
| 83 | +        <%= link_to destroy_all_jobs_path, class: "btn btn-default", method: :delete, data: { confirm: "Are you sure you want to delete ALL pending jobs for all Huginn users?" } do %> | |
| 84 | + <span class="glyphicon glyphicon-remove"></span> Remove all jobs | |
| 85 | + <% end %> | |
| 82 | 86 | </div> | 
| 83 | 87 | </div> | 
| 84 | 88 | </div> | 
| @@ -16,10 +16,11 @@ | ||
| 16 | 16 |  | 
| 17 | 17 | <div class="btn-group"> | 
| 18 | 18 |          <%= link_to icon_tag('glyphicon-chevron-left') + ' Back', scenarios_path, class: "btn btn-default" %> | 
| 19 | +        <%= link_to icon_tag('glyphicon-plus') + ' New Agent', new_agent_path(scenario_id: @scenario.id), class: "btn btn-default" %> | |
| 19 | 20 |          <%= link_to icon_tag('glyphicon-random') + ' View Diagram', scenario_diagram_path(@scenario), class: "btn btn-default" %> | 
| 20 | 21 |          <%= link_to icon_tag('glyphicon-edit') + ' Edit', edit_scenario_path(@scenario), class: "btn btn-default" %> | 
| 21 | 22 | <% if @scenario.source_url.present? %> | 
| 22 | -          <%= link_to icon_tag('glyphicon-plus') + ' Update', new_scenario_imports_path(url: @scenario.source_url), class: "btn btn-default" %> | |
| 23 | +          <%= link_to icon_tag('glyphicon-refresh') + ' Update', new_scenario_imports_path(url: @scenario.source_url), class: "btn btn-default" %> | |
| 23 | 24 | <% end %> | 
| 24 | 25 |          <%= link_to icon_tag('glyphicon-share-alt') + ' Share', share_scenario_path(@scenario), class: "btn btn-default" %> | 
| 25 | 26 |          <%= link_to icon_tag('glyphicon-trash') + ' Delete', scenario_path(@scenario), method: :delete, data: { confirm: "This will remove the '#{@scenario.name}' Scenerio from all Agents and delete it.  Are you sure?" }, class: "btn btn-default" %> | 
| @@ -62,6 +62,7 @@ Huginn::Application.routes.draw do | ||
| 62 | 62 | end | 
| 63 | 63 | collection do | 
| 64 | 64 | delete :destroy_failed | 
| 65 | + delete :destroy_all | |
| 65 | 66 | end | 
| 66 | 67 | end | 
| 67 | 68 |  | 
| @@ -87,19 +87,35 @@ describe AgentsController do | ||
| 87 | 87 | end | 
| 88 | 88 | end | 
| 89 | 89 |  | 
| 90 | - describe "GET new with :id" do | |
| 91 | - it "opens a clone of a given Agent" do | |
| 92 | - sign_in users(:bob) | |
| 93 | - get :new, :id => agents(:bob_website_agent).to_param | |
| 94 | - expect(assigns(:agent).attributes).to eq(users(:bob).agents.build_clone(agents(:bob_website_agent)).attributes) | |
| 90 | + describe "GET new" do | |
| 91 | + describe "with :id" do | |
| 92 | + it "opens a clone of a given Agent" do | |
| 93 | + sign_in users(:bob) | |
| 94 | + get :new, :id => agents(:bob_website_agent).to_param | |
| 95 | + expect(assigns(:agent).attributes).to eq(users(:bob).agents.build_clone(agents(:bob_website_agent)).attributes) | |
| 96 | + end | |
| 97 | + | |
| 98 | + it "only allows the current user to clone his own Agent" do | |
| 99 | + sign_in users(:bob) | |
| 100 | + | |
| 101 | +        expect { | |
| 102 | + get :new, :id => agents(:jane_website_agent).to_param | |
| 103 | + }.to raise_error(ActiveRecord::RecordNotFound) | |
| 104 | + end | |
| 95 | 105 | end | 
| 96 | 106 |  | 
| 97 | - it "only allows the current user to clone his own Agent" do | |
| 98 | - sign_in users(:bob) | |
| 107 | + describe "with a scenario_id" do | |
| 108 | + it 'populates the assigned agent with the scenario' do | |
| 109 | + sign_in users(:bob) | |
| 110 | + get :new, :scenario_id => scenarios(:bob_weather).id | |
| 111 | + expect(assigns(:agent).scenario_ids).to eq([scenarios(:bob_weather).id]) | |
| 112 | + end | |
| 99 | 113 |  | 
| 100 | -      expect { | |
| 101 | - get :new, :id => agents(:jane_website_agent).to_param | |
| 102 | - }.to raise_error(ActiveRecord::RecordNotFound) | |
| 114 | + it "does not see other user's scenarios" do | |
| 115 | + sign_in users(:bob) | |
| 116 | + get :new, :scenario_id => scenarios(:jane_weather).id | |
| 117 | + expect(assigns(:agent).scenario_ids).to eq([]) | |
| 118 | + end | |
| 103 | 119 | end | 
| 104 | 120 | end | 
| 105 | 121 |  | 
| @@ -1,7 +1,6 @@ | ||
| 1 | 1 | require 'spec_helper' | 
| 2 | 2 |  | 
| 3 | 3 | describe JobsController do | 
| 4 | - | |
| 5 | 4 | describe "GET index" do | 
| 6 | 5 | before do | 
| 7 | 6 | async_handler_yaml = | 
| @@ -75,8 +74,19 @@ describe JobsController do | ||
| 75 | 74 | end | 
| 76 | 75 |  | 
| 77 | 76 | it "just destroy failed jobs" do | 
| 78 | -      expect { delete :destroy_failed, id: @failed.id }.to change(Delayed::Job, :count).by(-1) | |
| 79 | -      expect { delete :destroy_failed, id: @running.id }.to change(Delayed::Job, :count).by(0) | |
| 77 | +      expect { delete :destroy_failed }.to change(Delayed::Job, :count).by(-1) | |
| 78 | + end | |
| 79 | + end | |
| 80 | + | |
| 81 | + describe "DELETE destroy_all" do | |
| 82 | + before do | |
| 83 | + @failed = Delayed::Job.create(failed_at: Time.now - 1.minute) | |
| 84 | + @running = Delayed::Job.create(locked_at: Time.now, locked_by: 'test') | |
| 85 | + sign_in users(:jane) | |
| 86 | + end | |
| 87 | + | |
| 88 | + it "destroys all jobs" do | |
| 89 | +      expect { delete :destroy_all }.to change(Delayed::Job, :count).by(-2) | |
| 80 | 90 | end | 
| 81 | 91 | end | 
| 82 | 92 | end |